//选择城市事件
function chooseCity() {
    var city_no = $("#city option:selected").val();
    $('.area_option').hide();
    $('.parent_id_'+city_no).show();
    $('.parent_id_'+city_no+':first').each(function () {
        $("#area").find("option[value="+$(this).val()+"]").attr("selected",true);
    })
}

function deleteImg() {
    $('#customer_img').attr('src','');
}

function addImages(customer_img) {
    $('#customer_img').attr('src',customer_img);
}

//保存编辑
function saveEdit() {
    var customer_name = $('#customer_name').val();
    if(checkIsNull(customer_name)){
        alertTips("请填写店铺名！");
        return false;
    }

    var city = $("#city option:selected").val();
    if(checkIsNull(city)){
        alertTips("请选择城市！");
        return false;
    }
    var area = $("#area option:selected").val();
    if(checkIsNull(area)){
        alertTips("请选择区域！");
        return false;
    }
    var address = $('#address').val();
    if(checkIsNull(address)){
        alertTips("请填写地址！");
        return false;
    }
    var customer_mobile = $('#customer_mobile').val();
    if(checkIsNull(customer_mobile)){
        alertTips("请填写手机号！");
        return false;
    }
    var customer_contact_name = $('#customer_contact_name').val();
    if(checkIsNull(customer_contact_name)){
        alertTips("请填写联系人！");
        return false;
    }
    var customer_img = $('#customer_img').attr('src');
    if(checkIsNull(customer_img)){
        alertTips("请上传照片！");
        return false;
    }
    var channel_type_no = $("#channel_type_no option:selected").val();
    if(checkIsNull(channel_type_no)){
        alertTips("请选择渠道类型！");
        return false;
    }
    var sms_code = $('#sms-code').val();
    if(checkIsNull(sms_code)){
        alertTips("请填写手机验证码！");
        return false;
    }

    $.ajax({
        type: "post",
        url: '/user/registerShop.do',
        dataType: "json",
        data: {
            'customer_name':customer_name,
            'city':city,
            'area':area,
            'address':address,
            'customer_mobile':customer_mobile,
            'customer_contact_name':customer_contact_name,
            'customer_img':customer_img,
            'channel_type_no':channel_type_no,
            'sms_code':sms_code
        },
        success: function(resp){
            console.log(resp);
            if(resp.result==="success"){
                alertTips("注册成功！");
                location.href=ctx+'/';
            }else{
                alertTips(resp.msg);
            }
        }
    });
}

var sms_type="register_sms";
function getSmsCode() {
    var mobile = $('#customer_mobile').val();
    sendSmsCode(mobile,sms_type);
}